package com.bingfor.easycablelink.home.Fragment.logistical;

import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;

import com.bingfor.easycablelink.R;
import com.bingfor.easycablelink.base.BaseActivity;
import com.bingfor.easycablelink.base.BaseFragment;
import com.bingfor.easycablelink.base.ViewPagerFragmentAdapter;
import com.bingfor.easycablelink.base.WebViewActivity;
import com.bingfor.easycablelink.databinding.ActivityLogisticalListBinding;
import com.bingfor.easycablelink.utils.ActivityUtil;
import com.bingfor.easycablelink.widgets.BannerLayout;

import java.util.ArrayList;
import java.util.List;

/**
* 配套产品详情
*@author LY
*@time 2017/5/26 16:34
* des:create file and achieve model
*/
public class LogisticalListActivity extends BaseActivity {

    ActivityLogisticalListBinding binding;
    List<String> urls = new ArrayList<>();
    TabLayout mTabLayout;
    List<String> titleList = new ArrayList<>();
    List<BaseFragment> fragmentList = new ArrayList<>();
    ViewPagerFragmentAdapter adapter ;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = ActivityLogisticalListBinding.inflate(getLayoutInflater());
        setContentView(binding.getRoot());
        initToolbar();
    }

    @Override
    public void initViews() {
        urls.add("http://img5.imgtn.bdimg.com/it/u=106339554,2370073595&fm=23&gp=0.jpg");
        urls.add("http://img4.imgtn.bdimg.com/it/u=4280242529,4076131167&fm=11&gp=0.jpg");
        urls.add("http://img4.imgtn.bdimg.com/it/u=3751624096,3567140332&fm=23&gp=0.jpg");
        urls.add("http://img0.imgtn.bdimg.com/it/u=3416815408,1559970174&fm=23&gp=0.jpg");

        binding.mBannerLayout.setViewUrls(urls);
        binding.mBannerLayout.setOnBannerItemClickListener(new BannerLayout.OnBannerItemClickListener() {
            @Override
            public void onItemClick(int position){
                Bundle bundle = new Bundle();
                bundle.putString("url","https://www.baidu.com");
                bundle.putString("title","品牌详情");
                bundle.putString("flag","1");
                ActivityUtil.getAppManager().move2NextPage(WebViewActivity.class,bundle);
            }
        });

        mTabLayout = $(R.id.mTabLayout);
        ViewPager mViewPager = $(R.id.mViewPager);
        adapter = new ViewPagerFragmentAdapter(mContext.getSupportFragmentManager(), fragmentList, titleList);
        mViewPager.setAdapter(adapter);
        mViewPager.setOffscreenPageLimit(10);
        mTabLayout.setupWithViewPager(mViewPager);
        initData();
    }
    private void initData(){
        titleList.add("开关插座");
        titleList.add("低压配电");
        titleList.add("电线电缆");
//        titleList.add("钢架壁纸");
//
        fragmentList.add( LogisticalPage.getInstance(0)) ;
        fragmentList.add( LogisticalPage.getInstance(1));
//        fragmentList.add( LogisticalPage.getInstance(2));
        fragmentList.add( LogisticalPage.getInstance(3));

        for (int i = 0; i <3; i++) {

            Bundle bundle = new Bundle();
            bundle.putSerializable("item",titleList.get(i));
            bundle.putInt("id",i);
            fragmentList.get(i).setArguments(bundle);
            titleList.add(i+"");
        }
        adapter.notifyDataSetChanged();
    }

    @Override
    public void initToolbar() {
        Toolbar toolbar = $(R.id.toolbar);
        setSupportActionBar(toolbar);
        getSupportActionBar().setDisplayHomeAsUpEnabled(true);
        setTitle("品牌报价");
        initViews();
    }

    @Override
    public void refresh() {

    }
}
